﻿using IRepositories;
using iService;
using iService.BASE;
using Repositories;
using Service.BASE;
using swiftCode.Bbs.Model.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Service
{
    public class PostService : BaseServices<Post>, IPostService
    {
        //public IPostRepositories dal = new PostRepositories();

        public readonly IPostRepositories dal;
        public PostService(IPostRepositories dalRep)
        {
            dal = dalRep;
        }

        public async Task DeleteArticleById(Expression<Func<Post, bool>> expression, bool autoSave = false)
        {
            await dal.DeleteAsync(expression, autoSave);
        }

        public async Task<Post> FindSingleById(Expression<Func<Post, bool>> expression)
        {
            return await dal.FindAsync(expression);
        }

        public async Task<List<Post>> GetAllArticles()
        {
            return await dal.GetListAsync();
        }

        public async Task<Post> PostArticle(Post post, bool autoSave = false)
        {
            return await dal.InsertAsync(post,autoSave);
        }

        public async Task<List<Post>> SelectArticle(Expression<Func<Post, bool>> expression)
        {
            return await dal.GetListAsync(expression);
        }

        public async Task<Post> UpdateArticle(Post post, bool autoSave = false)
        {
            var updatedPost = await dal.UpdateAsync(post, autoSave);
            return updatedPost;
        }
    }
}
